package cs551.listtracker.structure;

import org.simpleframework.xml.Attribute;

import android.os.Parcel;
import android.os.Parcelable;

public class ListItem implements Parcelable {
	public static final Parcelable.Creator<ListItem> CREATOR = new Parcelable.Creator<ListItem>() {
		public ListItem createFromParcel(Parcel source) {
			return new ListItem(source);
		}

		@Override
		public ListItem[] newArray(int size) {
			return new ListItem[size];
		}
	};

	@Attribute(name = "Title")
	public String title;

	@Attribute(name = "Quantity")
	public int quantity;

	@Attribute(name = "Cost")
	public double cost;

	@Attribute(name = "Checked")
	public boolean checked;

	// static String time;

	public ListItem(String title, int quantity, double cost) {
		if (title == null)
			this.title = "<unnamed>";
		else
			this.title = title;
		this.quantity = quantity;
		this.cost = cost;

		// Time t = new Time(Time.getCurrentTimezone());
		// t.setToNow();
		// time = t.format("%d.%m.%Y %H:%M:%S");
	}

	public ListItem(Parcel source) {
		this.title = source.readString();
		this.quantity = source.readInt();
		this.cost = source.readDouble();
		this.checked = source.readByte() != 0;
	}

	public ListItem() {
		this.title = "";
		this.quantity = 0;
		this.cost = 0;
		this.checked = false;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeString(title);
		out.writeInt(quantity);
		out.writeDouble(cost);
		out.writeByte((byte) (checked ? 1 : 0));
		// out.writeString(time);
	}

	public ListItem duplicate() {
		ListItem cloneItem = new ListItem();
		cloneItem.title = title;
		cloneItem.quantity = quantity;
		cloneItem.cost = cost;
		cloneItem.checked = checked;

		return cloneItem;
	}

}
